import React, { useEffect } from 'react';
import { connect } from 'umi';
import type { AppStateType } from '@/models/app';
import Home from './home';
import { getParamsString } from '@/utils';
import { getOnlineCashierid } from '@/service';

type App = {
  initApp: any;
  app?: AppStateType;
};

const App: React.FC<App> = (props) => {
  const uniacid: any = getParamsString('uniacid');
  const store_id: any = getParamsString('store_id');
  const table_id: any = getParamsString('table_id');
  console.log(uniacid, store_id, table_id);

  useEffect(() => {
    props.initApp({
      a: 'a',
    });

    // getOnlineCashierid({
    //   uniacid: uniacid,
    //   store_id: store_id,
    // }).then(res => {
    //   console.log(res)
    //   if (res.data) {
    //     props.initApp({
    //       table_id,
    //       uniacid,
    //       store_id,
    //       cashier_id: res.data,
    //     });
    //   } else {
    //     console.log('缺少参数')
    //   }
    // })
  }, []);

  return (
    <>
      <Home />
    </>
  );
};

export default connect(
  ({
    app,
    loading,
  }: {
    app: AppStateType;
    loading: {
      effects: Record<string, boolean>;
    };
  }) => {
    return {
      app,
      loading,
    };
  },
  (dispatch) => {
    return {
      initApp: (p: any) => {
        dispatch({
          type: 'app/init',
          data: p,
        });
      },
    };
  },
)(App);
